﻿<%@ Page Language="c#" Inherits="WinnerCMS.WebUI.Admin.Gather.Add" CodeBehind="Add.aspx.cs" %>

<%@ Register Src="../UC_AjaxLoading.ascx" TagName="UC_AjaxLoading" TagPrefix="uc1" %>

<!doctype html>
<html>
<head runat="server">
    <title>添加采集任务</title>
    <meta http-equiv="Pragma" content="No-cach" />
    <%: Styles.Render("~/Content/Bootstrap/css") %>
    

    <%: Scripts.Render("~/Scripts/AdminBase") %>
    <%: Scripts.Render("~/Scripts/easyui/easyui.js") %>

    <script type="text/javascript">
        $(function () { 
            ToLineNum();
            $("#txtFilter").keyup(function (event) { show_ln(event); });

            $("#txtReplace").keyup(function (event) { show_ln(event); });
        });
        function CheckForm() {
            if (document.getElementById("ddlArticleClass").value == 0) {
                alert("请选择栏目！");
                document.getElementById("ddlArticleClass").focus();
                return false;
            }
            if (document.getElementById("txtStartUrl").value == "") {
                alert("请填写列表开始地址！");
                document.getElementById("txtStartUrl").focus();
                return false;
            }
            if (document.getElementById("txtContentPageUrl").value == "") {
                alert("文章页链接！");
                document.getElementById("txtContentPageUrl").focus();
                return false;
            }
            if (document.getElementById("txtContentTitle").value == "") {
                alert("文章标题！");
                document.getElementById("txtContentTitle").focus();
                return false;
            }
            if (document.getElementById("txtContent").value == "") {
                alert("文章内容！");
                document.getElementById("txtContent").focus();
                return false;
            }
        }

        function show_ln(event) {
            var iadd = 1;
            var obj = event.srcElement ? event.srcElement : event.target;
            var str;
            var x;
            var i;
            if (obj == $get("txtFilter")) {
                x = $get("txtFilter").value.split('\n').length + iadd;
                str = '';
                for (i = 1; i < x; i++)
                    str += i + '\n';

                $get("txt_ln").value = str;
                $get("txt_ln").scrollTop = $get("txtFilter").scrollTop;
            }
            if (obj == $get("txtReplace")) {
                x = $get("txtReplace").value.split('\n').length + iadd;
                str = '';
                for (i = 1; i < x; i++) {
                    str += i + '\n';
                }

                document.getElementById('txt_ln2').value = str;
            }
        }

        function toDoc(cId, str) {
            $get(cId).value = $get(cId).value + str;
            return false;
        }
        function ToLineNum() {
            for (var i = 0; i < ($get("txtFilter").value.split('\n').length) ; i++)
                document.getElementById('txt_ln').value += (i + 1) + '\n';
            for (var i = 0; i < ($get("txtReplace").value.split('\n').length) ; i++)
                document.getElementById('txt_ln2').value += (i + 1) + '\n';
        }

        function TestClassResult() {
            $('#TestResult').window('open');

            $.ajax({
                type: "POST",     //HTTP 请求方法,默认: "GET"  
                url: "GatherClass.ashx?Action=Test&N=" + Math.random(),   //发送请求的地址  
                data: {
                    StartUrl: $("#txtStartUrl").val(),
                    CategoryArea: $("#txtCategoryArea").val(),
                    ShowArticleUrl: $("#txtContentPageUrl").val(),
                    ClassNextPage: $("#txtCategoryPageNextUrl").val()
                },
                dataType: "json",         //预期服务器返回的数据类型  
                success: function (info) {
                    if (info.errors != "") {
                        alert(info.errors);
                        return;
                    }
                    var dialogContent = "";
                    for (var i = 0; i < info.Urls.length; i++) {
                        dialogContent += info.Urls[i] + "\r\n";
                    }
                    $("#DialogContent").val(dialogContent).show();
                    $("#DialogLoading").hide();

                },
                error: function (msg) {
                    $("#DialogContent").show();
                    $("#DialogLoading").hide();
                    alert(msg);
                }
            });
        }

    </script>
    <style type="text/css">
        .style1 {
            color: #ff0000;
        }
    </style>
</head>
<body>
    <form id="Form1" method="post" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdateProgress ID="UpdateProgress1" runat="server">
            <ProgressTemplate>
                <uc1:UC_AjaxLoading ID="UC_AjaxLoading1" runat="server" />
            </ProgressTemplate>
        </asp:UpdateProgress>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <fieldset>
                    <legend><strong>基本设置</strong></legend>
                    <table width="98%" align="center">
                        <tr>
                            <td align="right" style="width: 146px">任务名称：
                            </td>
                            <td>
                                <asp:TextBox ID="txtGatherName" runat="server" Width="200px"></asp:TextBox>
                                <span class="style1">*</span>
                            </td>
                            <td>
                                <img title="复制相似的采集规则" height="16" src="../../Images/help.gif" width="16" alt="" />复制任务：
                            <WinnerCMS:DropDownListX ID="ddlGather" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlGather_SelectedIndexChanged"
                                onchange="ToLineNum();">
                            </WinnerCMS:DropDownListX>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">列表开始地址：
                            </td>
                            <td colspan="2">
                                <asp:TextBox ID="txtStartUrl" runat="server" Width="528px" Rows="3"
                                    TextMode="MultiLine"></asp:TextBox>
                                <span class="style1">*</span>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">下载站外图片：
                            </td>
                            <td colspan="2" align="left">
                                <asp:RadioButtonList ID="RBL_DownImg" runat="server" RepeatDirection="Horizontal" CssClass="icheckboxStyle">
                                    <asp:ListItem Value="是">是</asp:ListItem>
                                    <asp:ListItem Value="否" Selected="True">否</asp:ListItem>
                                </asp:RadioButtonList>
                                当上面选择"是",如果不下载站外图片,则保持外链别人的图片.
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                <img title="当且仅当选择了下载图片的时候生效" height="16" src="../../Images/help.gif" width="16">是否加水印：
                            </td>
                            <td colspan="2" align="left">
                                <asp:RadioButtonList ID="RBL_DrawWaterMark" runat="server" RepeatDirection="Horizontal" CssClass="icheckboxStyle">
                                    <asp:ListItem Value="是">是</asp:ListItem>
                                    <asp:ListItem Value="否" Selected="True">否</asp:ListItem>
                                </asp:RadioButtonList>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">通过审核：
                            </td>
                            <td colspan="2" align="left">
                                <asp:RadioButtonList ID="RBL_Pass" runat="server" RepeatDirection="Horizontal" CssClass="icheckboxStyle">
                                    <asp:ListItem Value="是">是</asp:ListItem>
                                    <asp:ListItem Value="否" Selected="True">否</asp:ListItem>
                                </asp:RadioButtonList>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">采往哪个栏目：
                            </td>
                            <td colspan="2">
                                <WinnerCMS:DropDownListX ID="ddlArticleCategory" runat="server">
                                </WinnerCMS:DropDownListX>
                            </td>
                        </tr>
                    </table>
                </fieldset>
                &nbsp;
            <br>
                <fieldset>
                    <legend><strong>栏目匹配规则</strong></legend>
                    <table cellpadding="3" width="98%" align="center">
                        <tr>
                            <td align="right" style="width: 140px">扫描栏目页范围： 
                            </td>
                            <td>
                                <asp:TextBox ID="txtCategoryArea" runat="server" Width="528px" TextMode="MultiLine"></asp:TextBox>
                                <a href="Rule.aspx" target="_blank"><strong>规则生成器</strong></a></td>
                        </tr>
                        <tr>
                            <td align="right">文章页链接：
                            </td>
                            <td>
                                <asp:TextBox ID="txtContentPageUrl" runat="server" Width="528px" TextMode="MultiLine"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">栏目下一页：
                            </td>
                            <td>
                                <asp:TextBox ID="txtCategoryPageNextUrl" runat="server" Width="528px" TextMode="MultiLine"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">忽略采集的URL：</td>
                            <td>
                                <asp:TextBox ID="txtIgnoreUrl" runat="server" TextMode="MultiLine"
                                    Width="528px"></asp:TextBox>
                                正则表达式</td>
                        </tr>
                        <tr>
                            <td align="right">&nbsp;
                            </td>
                            <td><a href="javascript:void(0)" onclick="TestClassResult();">查看采集结果</a></td>
                        </tr>
                    </table>
                </fieldset>
                <br>
                <fieldset>
                    <legend><strong>文章匹配规则</strong></legend>
                    <table cellpadding="3" width="98%" align="center">
                        <tr>
                            <td align="right" style="width: 140px">标题： <span class="style1">*</span>
                            </td>
                            <td>
                                <asp:TextBox ID="txtContentTitle" runat="server" Width="528px" TextMode="MultiLine"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">内容：
                            </td>
                            <td>
                                <asp:TextBox ID="txtContent" runat="server" Width="528px" TextMode="MultiLine"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">作者：
                            </td>
                            <td>
                                <asp:TextBox ID="txtAuthor" runat="server" Width="528px" TextMode="MultiLine"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">来源：
                            </td>
                            <td>
                                <asp:TextBox ID="txtFrom" runat="server" Width="528px" TextMode="MultiLine"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">日期：
                            </td>
                            <td>
                                <asp:TextBox ID="txtUpdateTime" runat="server" Width="528px" TextMode="MultiLine"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">文章页下一页地址：
                            </td>
                            <td>
                                <asp:TextBox ID="txtContentPageNextUrl" runat="server" Width="528px" TextMode="MultiLine"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">全文文章页地址：</td>
                            <td>
                                <asp:TextBox ID="txtFullArticleUrl" runat="server" Width="528px" TextMode="MultiLine"></asp:TextBox>
                            </td>
                        </tr>
                    </table>
                </fieldset>
                <br>
                <fieldset>
                    <legend><strong>内容过滤与替换</strong></legend>
                    <table cellpadding="3" width="98%" align="center">
                        <tr>
                            <td align="right" style="width: 110px">
                                <img title="每项设置用回车键分割" alt="" height="16" src="../../Images/help.gif" width="16" />过滤内容：
                            </td>
                            <td style="width: 600px">
                                <textarea id='txt_ln' name='content' rows='10' cols='4' style='overflow: hidden; height: 200px; width: 28.8px; border-right: 0px; text-align: right; background: #d0d0d0;' readonly="readonly"></textarea>
                                <asp:TextBox ID="txtFilter" runat="server" ToolTip="支持正则表达式" Rows="10"
                                    TextMode="MultiLine"
                                    Style="overflow: hidden; height: 200px; padding-left: 5px; border-left: 0px"
                                    Columns="64" Wrap="False" Width="500px"></asp:TextBox>
                            </td>
                            <td>
                                <table style="width: 100%;">
                                    <tr>
                                        <td>
                                            <a href="javascript:void(0)" onclick="toDoc('txtFilter','<IFRAME[^>]*?>[\\s\\S]*?</IFRAME>')">IFRAME</a>
                                        </td>
                                        <td>
                                            <a href="javascript:void(0)" onclick="toDoc('txtFilter','<TABLE[^>]*?>[\\s\\S]*?</TABLE>')">TABLE</a>
                                        </td>
                                        <td>
                                            <a href="javascript:void(0)" onclick="toDoc('txtFilter','<FORM[^>]*?>[\\s\\S]*?</FORM>')">FORM</a>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <a href="javascript:void(0)" onclick="toDoc('txtFilter','<OBJECT[^>]*?>[\\s\\S]*?</OBJECT>')">OBJECT</a>
                                        </td>
                                        <td>
                                            <a href="javascript:void(0)" onclick="toDoc('txtFilter','<SCRIPT[^>]*?>[\\s\\S]*?</SCRIPT>')">SCRIPT</a>
                                        </td>
                                        <td>
                                            <a href="javascript:void(0)" onclick="toDoc('txtFilter','<STYLE[^>]*?>[\\s\\S]*?</STYLE>')">STYLE</a>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <a href="javascript:void(0)" onclick="toDoc('txtFilter','<FONT[^>]*?>[\\s\\S]*?</FONT>')">FONT</a>
                                        </td>
                                        <td>
                                            <a href="javascript:void(0)" onclick="toDoc('txtFilter','<SPAN[^>]*?>[\\s\\S]*?</SPAN>')">FONT</a>
                                        </td>
                                        <td>
                                            <a href="javascript:void(0)" onclick="toDoc('txtFilter','<A[^>]*?>[\\s\\S]*?</A>')">FONT</a>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                <img alt="" title="每项设置要跟上面的一一对应。" height="16" src="../../Images/help.gif" width="16" />被替换为：
                            </td>
                            <td>
                                <textarea id='txt_ln2' name='content' rows='10' cols='4' style='overflow: hidden; height: 200px; width: 28.8px; border-right: 0px; text-align: right; background: #d0d0d0;'></textarea>
                                <asp:TextBox ID="txtReplace" runat="server" ToolTip="支持正则表达式" Rows="10" TextMode="MultiLine"
                                    Style="overflow: hidden; height: 200px; padding-left: 5px; border-left: 0px" Columns="64"
                                    Wrap="False" Width="500px"></asp:TextBox>
                            </td>
                            <td>&nbsp;
                            </td>
                        </tr>
                        <tr>
                            <td align="center" colspan="2" height="30">
                                <asp:Button ID="btnGatherAdd" runat="server" Text="提交" OnClick="btnGatherAdd_Click"
                                    Cssclass="btn btn-default"></asp:Button>
                            </td>
                            <td align="center" height="30">&nbsp;
                            </td>
                        </tr>
                    </table>
                </fieldset>
            </ContentTemplate>
        </asp:UpdatePanel>
    </form>
    <div id="TestResult" closed="true" class="easyui-window" modal="true" resizable="false" maximizable="true"
        title="测试查看" style="width: 500px; height: 400px;">
        <div id="DialogLoading" style="width: 100%; height: 100%;">正在加载...</div>
        <textarea id="DialogContent" rows="10" cols="80" style="width: 479px; height: 340px; display: none"></textarea>
    </div>
</body>
</html>
